<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>滚动事件</title>
</head>
<body>
    <div id="div1" style="width:100%;height:1000px;border:solid 1px red;"></div>
    <button id="btn">按钮</button>
    <div id="div2" style="width:100%;height:1000px;border:solid 1px green;"></div>
    <button id="btn2">按钮</button>
    <script src="__JS__/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        //浏览器窗口高度
        var winHei=$(window).height();
        //滚动条距离页面顶部的高度
        var sTop=$(window).scrollTop();
        // console.log(sTop);
        //元素距页面顶部的高度
        var btnToTop=$('#btn').offset().top;
        // console.log(btnToTop);
        var btnToTop1=$('#btn2').offset().top;
        //滚动世界
        $(window).bind('scroll',function(){
            //滚动条距离页面顶部的高度
            var sTop=$(window).scrollTop();
            //console.log(sTop);

            if(sTop+winHei>=btnToTop){
                $('#div1').css({background:'red'});
            }
            if(sTop+winHei>=btnToTop1){
                $('#div2').css({background:'yellow'});
            }
        });
    </script>
</body>
</html>